﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             xmlns:OpenLightGroup_Common_UserManagement_Web="clr-namespace:OpenLightGroup.Common.UserManagement.Web"
             xmlns:local="clr-namespace:OpenLightGroup.Common.UserManagement"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             mc:Ignorable="d"
             x:Class="OpenLightGroup.Common.UserManagement.UserEditor"
             d:DesignWidth="640"
             d:DesignHeight="480">
    <UserControl.Resources>

        <Style TargetType="TextBox"
               x:Key="UserEditorTextBox">
            <Setter Property="Margin"
                    Value="5,5,0,5" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="Width"
                    Value="200" />
        </Style>

        <Style TargetType="PasswordBox"
               x:Key="UserEditorPasswordBox">
            <Setter Property="Margin"
                    Value="5,5,0,5" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="Width"
                    Value="200" />
        </Style>

        <Style TargetType="TextBlock"
               x:Key="UserEditorTextBlock">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="Margin"
                    Value="3,0,0,0" />
        </Style>
        <DataTemplate x:Key="RolesTreeViewDataTemplate">
            <Grid>
                <CheckBox x:Name="checkBox"
                          Content="{Binding Name}"
                          Margin="0,0,0,3"
                          d:LayoutOverrides="Width, Height" />
            </Grid>
        </DataTemplate>


    </UserControl.Resources>

    <d:DataContext>
        <local:UserManagementViewModel />
    </d:DataContext>

    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="EditingStates">
                <VisualState x:Name="CreateUser" />
                <VisualState x:Name="EditUser">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBox.IsReadOnly)"
                                                       Storyboard.TargetName="UsernameTextBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <System:Boolean>True</System:Boolean>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="PasswordTextBlock">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="PasswordBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="ConfirmPasswordTextBlock">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                       Storyboard.TargetName="ConfirmPasswordBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto"
                              MinWidth="200" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock x:Name="UsernameTextBlock"
                   Text="Username:"
                   Style="{StaticResource UserEditorTextBlock}" />
        <TextBox x:Name="UsernameTextBox"
                 Grid.Column="1"
                 Style="{StaticResource UserEditorTextBox}"
                 HorizontalAlignment="Stretch"
                 Margin="5"
                 Width="Auto"
                 Text="{Binding NewUser.UserName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="EmailAddressTextBlock"
                   Text="Email:"
                   Grid.Row="1"
                   Style="{StaticResource UserEditorTextBlock}" />
        <TextBox x:Name="EmailAddressTextBox"
                 Grid.Row="1"
                 Grid.Column="1"
                 Style="{StaticResource UserEditorTextBox}"
                 HorizontalAlignment="Stretch"
                 Margin="5"
                 Width="Auto"
                 Text="{Binding NewUser.Email, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="PasswordTextBlock"
                   Text="Password:"
                   Grid.Row="2"
                   Style="{StaticResource UserEditorTextBlock}" />
        <PasswordBox x:Name="PasswordBox"
                     Grid.Column="1"
                     Grid.Row="2"
                     Style="{StaticResource UserEditorPasswordBox}"
                     HorizontalAlignment="Stretch"
                     Margin="5"
                     Width="Auto"
                     Password="{Binding NewUser.Password, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="ConfirmPasswordTextBlock"
                   Text="Confirm Password:"
                   Grid.Row="3"
                   Style="{StaticResource UserEditorTextBlock}" />
        <PasswordBox x:Name="ConfirmPasswordBox"
                     Grid.Column="1"
                     Grid.Row="3"
                     Style="{StaticResource UserEditorPasswordBox}"
                     HorizontalAlignment="Stretch"
                     Margin="5"
                     Width="Auto"
                     Password="{Binding NewUser.Password, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="SecurityQuestionTextBlock"
                   Text="Security Question:"
                   Grid.Row="4"
                   Style="{StaticResource UserEditorTextBlock}" />
        <TextBox x:Name="SecurityQuestionTextBox"
                 Grid.Column="1"
                 Grid.Row="4"
                 Style="{StaticResource UserEditorTextBox}"
                 HorizontalAlignment="Stretch"
                 Margin="5"
                 Width="Auto"
                 Text="{Binding NewUser.Question, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="SecurityAnswerTextBlock"
                   Text="Security Answer:"
                   Grid.Row="5"
                   Style="{StaticResource UserEditorTextBlock}" />
        <TextBox x:Name="SecurityAnswerTextBox"
                 Grid.Column="1"
                 Grid.Row="5"
                 Style="{StaticResource UserEditorTextBox}"
                 HorizontalAlignment="Stretch"
                 Margin="5"
                 Width="Auto"
                 Text="{Binding NewUser.Answer, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
        <TextBlock x:Name="textBlock"
                   Grid.Column="2"
                   HorizontalAlignment="Left"
                   Margin="5,0,0,0"
                   TextWrapping="Wrap"
                   Text="Select roles for this user:"
                   d:LayoutOverrides="Height"
                   VerticalAlignment="Center" />
        <local:UserRolesManager Grid.Column="2"
                                Margin="5,0,0,0"
                                d:LayoutOverrides="Height"
                                Grid.Row="1"
                                Grid.RowSpan="5"
                                User="{Binding NewUser, Mode=TwoWay}" />
    </Grid>
</UserControl>